/********************************************************************
* Copyright (c) 2013,TGS,All rights reserved.
* fileName:	RubberBand.h	
* created:	2013/04/26 17:57

* version:	1.6
* detail: 
*********************************************************************/

#pragma once


#include "MapCanvasItem.h"
#include <TGS/GeoMath2.0/Point.h>
#include <QBrush>
#include <QList>
#include <QPen>
#include <QPolygon>
#include <QWidget>


namespace TGS{
namespace GeoMath{
	class Polygon;
}}

class QPaintEvent;
class QPointF;

namespace TGS{
namespace MapControl{

class MapCanvas	;


/** \ingroup gui
* A class for drawing transient features (e.g. digitising lines) on the map.
*/
class RubberBand : public MapCanvasItem
{
	typedef TGS::GeoMath::Point Point;
	typedef TGS::GeoMath::Polygon Polygon;
public:
	RubberBand();
	RubberBand( MapCanvas* mapCanvas, bool isPolygon = false );
	~RubberBand();
public:
	Polygon getPolygon() const;
public:
	void setColor( const QColor & color );
	void setWidth( int width );

	void reset( bool isPolygon = false );

	//! Add point to rubberband and update canvas
	//! If adding more points consider using update=false for better performance
	//! geometryIndex is the index of the feature part (in case of multipart geometries)
	void addPoint( const Point & p, bool update = true, int geometryIndex = 0 );

	//!Removes the last point. Most useful in connection with undo operations
	void removeLastPoint( int geometryIndex = 0 );

	void movePoint( const Point & p, int geometryIndex = 0 );
	/**Moves the rubber band point specified by index. Note that if the rubber band is
	not used to track the last mouse position, the first point of the rubber band has two vertices*/
	void movePoint( int index, const Point& p, int geometryIndex = 0 );

	/**Sets this rubber band to a map canvas rectangle
	@param rect rectangle in canvas coordinates
	@note added in version 1.7*/
	void setToCanvasRectangle( const QRect& rect );

	/**Adds translation to original coordinates (all in map coordinates)*/
	void setTranslationOffset( double dx, double dy );

	/**Returns number of geometries
	* added in 1.5 */
	int size() const;

	/**Returns count of vertices in all lists of mPoint*/
	int numberOfVertices() const;

	/**Return vertex*/
	const Point *getPoint( int i, int j = 0 ) const;
protected:
	virtual void paint( QPainter* p );

	//! recalculates needed rectangle
	void updateRect();
private:
	QBrush _brush;
	QPen _pen;

	/**Nested lists used for multitypes*/
	QList< QList <Point> > _points;
	bool _isPolygon;
	double _translationOffsetX;
	double _translationOffsetY;
	
};


}//MapControl
}//TGS